package com.haralabidis.jdeveloper.extension.subversionmonitor.addin.editor;


import java.awt.BorderLayout;

import java.net.URL;

import javax.swing.JComponent;
import javax.swing.JScrollPane;
import javax.swing.JTabbedPane;
import javax.swing.UIManager;

import oracle.javatools.ui.TransparentPanel;
import oracle.javatools.ui.plaf.FlatTabbedPaneUI;


/**
 * The main GUI component of the example flat editor.
 */
// Note: we extend TransparentPanel to make sure that we contain no opaque
// components. In general, it's a good idea to use TransparentPanel as the
// parent of all containers in a flat editor.
final class RevisionsEditorPanel extends TransparentPanel {
    private URL url = null;
    JTabbedPane tabbedPane = new JTabbedPane();
    JScrollPane sp;

    public void refresh(URL url) {
        tabbedPane.remove(sp);
        tabbedPane.add("General",
                       createScrollPane(new RevisionsGeneralPane(this.url)));
    }

    RevisionsEditorPanel(URL url) {

        this.url = url;

        setLayout(new BorderLayout());

        // Use the standard "finger tab" visual appearance for category tabs
        // in a flat editor.
        tabbedPane.setUI(new FlatTabbedPaneUI());

        addTabPages(tabbedPane);


        add(tabbedPane, BorderLayout.CENTER);
    }

    private void addTabPages(JTabbedPane tabbedPane) {
        tabbedPane.add("General",
                       createScrollPane(new RevisionsGeneralPane(this.url)));
        //        tabbedPane.add("Widgets", createScrollPane(new WidgetsPage()));
        //        tabbedPane.add("Sprockets", createScrollPane(new SprocketPage()));
    }

    /**
     * Creates a scrollpane for a tab page.
     */
    private JScrollPane createScrollPane(JComponent c) {
        sp = new JScrollPane(c);
        sp.setBorder(null);
        sp.getViewport().setBackground(UIManager.getColor("window"));
        sp.getVerticalScrollBar().setUnitIncrement(20);
        sp.getHorizontalScrollBar().setUnitIncrement(20);
        sp.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);

        return sp;
    }
}
